package com.ggchzzz.login;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.ggchzzz.login.bean.datas;
import com.ggchzzz.login.utils.http;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {
    private EditText name,password;
    private Button login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name=(EditText)findViewById(R.id.name);
        password=(EditText)findViewById(R.id.passwd);
        login=(Button)findViewById(R.id.login);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName=name.getText().toString();
                String passwd=password.getText().toString();
                Log.i("ggchzzz","账号是"+userName+","+"密码是"+passwd);
                http  httpService=new http();
                Call call= httpService.LoginAction(userName,passwd);
                call.enqueue(new Callback<datas>() {
                    @Override
                    public void onResponse(Call<datas> call, Response<datas> response) {
                        try {
                            Log.d("ggchzzz111",response.body().getToken());

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
//                        Toast.makeText(MainActivity.this, response.body().toString(), Toast.LENGTH_SHORT).show();
                    }
                    @Override
                    public void onFailure(Call call, Throwable t) {
                    }
                });
            }
        });
    }
}
